//
//  NET.m
//  KingSelected
//
//  Created by 杨鹏 on 2023/10/27.
//

#import "NET.h"

NSString *baseUrl = @"https://interface.456465465465465.top/smallShopInterface";

@implementation NET

+ (void)loginWithPhone:(NSString *)phone psd:(NSString *)password success:(void (^)(id _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userName"] = phone;
    param[@"password"] = password;
    [NetManager postWithUrl:URL(@"user/user-login") parameters:param needEncryption:NO success:success failure:failure];
}

/// 发送验证码
+ (void)sendCode:(NSString *)phone success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"phone"] = phone;
    [NetManager postWithUrl:URL(@"user/send-code") parameters:param needEncryption:NO success:success failure:failure];
}

/// 忘记密码验证码
+ (void)sendResetPsdCode:(NSString *)phone success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"phone"] = phone;
    [NetManager postWithUrl:URL(@"user/resetPwdSendCode") parameters:param needEncryption:NO success:success failure:failure];
}

/// 注册
+ (void)registeWithPhone:(NSString *)phone code:(NSString *)code psd:(NSString *)psd success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"code"] = code;
    param[@"userName"] = phone;
    param[@"password"] = psd;
    [NetManager postWithUrl:URL(@"user/user-register") parameters:param needEncryption:NO success:success failure:failure];
}

/// 重置密码
+ (void)resetPasswordWithPhone:(NSString *)phone code:(NSString *)code psd:(NSString *)psd success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"code"] = code;
    param[@"phone"] = phone;
    param[@"password"] = psd;
    [NetManager postWithUrl:URL(@"user/resetPwd") parameters:param needEncryption:NO success:success failure:failure];
}

/// 获取用户信息
+ (void)getUserInfo:(NSString *)userId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = userId;
    [NetManager postWithUrl:URL(@"user/user-info-get") parameters:param needEncryption:NO success:success failure:failure];
}

/// 更新用户信息
+ (void)updateUserInfo:(NSString *_Nullable)avatar name:(NSString *_Nullable)name success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"avatar"] = avatar;
    param[@"nickName"] = name;
    [NetManager postWithUrl:URL(@"user/user-info-save") parameters:param needEncryption:NO success:success failure:failure];
}

+ (void)uploadAvatar:(UIImage *)img success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSData *imagedata = [img compressWithMaxLength];
    [NetManager uploadWithURL:URL(@"common/uploadPic") parameters:nil fileData:@[imagedata] fileNames:@[@"file"] mimeType:nil progress:nil success:success failure:failure];
}

/// 获取店铺商品或搜索
+ (void)getShopListWithPage:(NSInteger)page pageSize:(NSInteger)pageSize userId:(NSString *)userId enable:(NSInteger)enable goodsIntroduction_Like:(NSString *_Nullable)goodsIntroduction_Like success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"pageIndex"] = @(page);
    param[@"pageSize"] = @(pageSize);
    param[@"userId"] = userId;
    param[@"enable"] = @(enable);
    param[@"goodsIntroduction_Like"] = goodsIntroduction_Like;
    [NetManager postWithUrl:URL(@"mall/otherIndex") parameters:param needEncryption:NO success:success failure:failure];
}

/// 删除商品
+ (void)deleteShopWithGoodsId:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/mall-goods-delete") parameters:param needEncryption:NO success:success failure:failure];
}

/// enable NO下架 YES 上架
+ (void)topOrDownShopWithGoodsId:(NSString *)goodsId enable:(BOOL)enable success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    param[@"enable"] = @(enable);
    [NetManager postWithUrl:URL(@"mall/mall-goods-enable") parameters:param needEncryption:NO success:success failure:failure];
}

/// 设置置顶
+ (void)topSetShopWithGoodsId:(NSString *)goodsId top:(BOOL)top success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    param[@"top"] = @(top);
    [NetManager postWithUrl:URL(@"mall/mall-goods-top") parameters:param needEncryption:NO success:success failure:failure];
}

+ (void)publishGoodsWithGoodsId:(NSString *_Nullable)goodsId goodsIntroduction:(NSString *)goodsIntroduction sellingPrice:(NSString *)sellingPrice imgUrl:(NSString *_Nullable)imgUrl imgThumbnailUrl:(NSString *_Nullable)imgThumbnailUrl video:(NSString *_Nullable)video videoImgUrl:(NSString *_Nullable)videoImgUrl success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    param[@"goodsIntroduction"] = goodsIntroduction;
    param[@"sellingPrice"] = sellingPrice;
    param[@"imgUrl"] = imgUrl;
    param[@"imgThumbnailUrl"] = imgThumbnailUrl;
    param[@"video"] = video;
    param[@"videoImgUrl"] = videoImgUrl;
    param[@"enable"] = @(YES);
    param[@"type"] = @"1";
    [NetManager postWithUrl:URL(@"mall/mall-goods-save") parameters:param needEncryption:NO success:success failure:failure];
}

/// 获取关注列表
+ (void)getFollowList:(NSNumber *)page size:(NSNumber *)pageSize success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"pageNumber"] = page;
    param[@"pageSize"] = pageSize;
    [NetManager postWithUrl:URL(@"user/user-follow-query") parameters:param needEncryption:NO success:success failure:failure];
}

/// 关注
+ (void)followUser:(NSString *)idolUserId flag:(BOOL)isFollow status:(NSInteger)status success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"idolUserId"] = idolUserId;
    param[@"flag"] = isFollow ? @"1" : @"0";
    param[@"status"] = @(status);
    [NetManager postWithUrl:URL(@"user/user-follow") parameters:param needEncryption:NO success:success failure:failure];
}

/// 置顶
+ (void)topUser:(NSString *)userId type:(BOOL)type success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = userId;
    param[@"type"] = type ? @"1" : @"0";
    [NetManager postWithUrl:URL(@"user/user-follow-top") parameters:param needEncryption:NO success:success failure:failure];
}

/// 搜索
+ (void)searchUser:(NSString *)nickName pageNumber:(NSNumber *)pageNumber pageSize:(NSNumber *)pageSize success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure; {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"nickName"] = nickName;
    param[@"pageNumber"] = pageNumber;
    param[@"pageSize"] = pageSize;
    [NetManager postWithUrl:URL(@"user/followSearch") parameters:param needEncryption:NO success:success failure:failure];
}

/// 获取商品详情
+ (void)getGoodsInfoWithGoodsId:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/goodsDetail") parameters:param needEncryption:NO success:success failure:failure];
}

/// 动态页面的商品列表
+ (void)getDynamicGoodsList:(NSNumber *)page pageSize:(NSNumber *)pageSize searchStr:(NSString *_Nullable)goodsIntroduction_Like success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"pageIndex"] = page;
    param[@"pageSize"] = pageSize;
    param[@"goodsIntroduction_Like"] = goodsIntroduction_Like;
    [NetManager postWithUrl:URL(@"mall/index") parameters:param needEncryption:NO success:success failure:failure];
}

/// 获取公告
+ (void)getNoticeDataSuccess:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    [NetManager postWithUrl:URL(@"user/notify-info-list") parameters:nil needEncryption:NO success:success failure:failure];
}

+ (void)getQrcodeSuccess:(void (^)(id _Nonnull))success failure:(void (^)(NSError * _Nonnull))failure {
    [NetManager postWithUrl:URL(@"user/QRCode") parameters:nil needEncryption:NO success:success failure:failure];
}

/// 一键转发
+ (void)forwardGoodsWithGoodsId:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/mall-goods-copy") parameters:param needEncryption:NO success:success failure:failure];
}

/// 同步更新商品
+ (void)updateGoodsWithGoodsId:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/mall-goods-async") parameters:param needEncryption:NO success:success failure:failure];
}

/// 售罄
+ (void)soldOutWithGoodsId:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/mall-goods-close") parameters:param needEncryption:NO success:success failure:failure];
}

/// 拉黑用户 1拉黑；0取消
+ (void)blackUser:(NSString *)userId type:(int)type success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = userId;
    param[@"type"] = @(type);
    [NetManager postWithUrl:URL(@"user/userBlankChange") parameters:param needEncryption:NO success:success failure:failure];
}

/// 用户列表
+ (void)getBlackListSuccess:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    [NetManager postWithUrl:URL(@"user/userBlankList") parameters:nil needEncryption:NO success:success failure:failure];
}

/// 获取商品二维码
+ (void)getGoodsQrCode:(NSString *)goodsId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsId"] = goodsId;
    [NetManager postWithUrl:URL(@"mall/mall-goods-QRCode") parameters:param needEncryption:NO success:success failure:failure];
}

/// 批量置顶
+ (void)topAllWithGoodsIds:(NSString *)goodsIds success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsIds"] = goodsIds;
    [NetManager postWithUrl:URL(@"mall/mall-goods-top-arr") parameters:param needEncryption:NO success:success failure:failure];
}

/// 批量上下架
+ (void)topDownAllWithGoodsIds:(NSString *)goodsIds enable:(NSInteger)enable success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsIds"] = goodsIds;
    param[@"enable"] = @(enable);
    [NetManager postWithUrl:URL(@"mall/mall-goods-enable-arr") parameters:param needEncryption:NO success:success failure:failure];
}

/// 批量删除
+ (void)deleteAllWithWithGoodsIds:(NSString *)goodsIds success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"goodsIds"] = goodsIds;
    [NetManager postWithUrl:URL(@"mall/mall-goods-delete-arr") parameters:param needEncryption:NO success:success failure:failure];
}

/// 设置跟随商家全自动半自动 1跟随商家上架、下架；2跟随商家下架，手动上架；
+ (void)followSetType:(NSInteger)type userId:(NSString *)userId success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure {
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = userId;
    param[@"status"] = @(type);
    [NetManager postWithUrl:URL(@"user/user-set-up-save") parameters:param needEncryption:NO success:success failure:failure];
}

@end
